/**
 * @project_name staff_vehicle
 * @package_name com.ssh.web.admin
 * @desc TODO
 * @param
 * @author jack
 * @date 2013-4-27
 * @time 下午10:45:27
 */
package com.ssh.web.admin;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ssh.entity.InnerVehicle;
import com.ssh.model.pdata.InnerVehicleUseInfo;
import com.ssh.model.pdata.StaffDepApplyCarMData;
import com.ssh.ser.admin.VehicleManageSerI;

/**
 * @author jack
 *
 */
public class QueryVehicleAction extends ActionSupport {

	/**
	 * TODO
	 */
	private static final long serialVersionUID = 1L;

	private Timestamp endTime;
	private List<InnerVehicleUseInfo> innerCarUseInfoList;
	private List<InnerVehicle> innerVehicleList;
	private List<StaffDepApplyCarMData> staffAMPDataList;// 传递数据
	private Timestamp startTime;
	private String state;
	private String type;
	private String vehicleId;
	private String vehicleLevel;
	private VehicleManageSerI vehicleManageSerI;
	private String vehiclePicture;

	/*
	 * (non-Javadoc)
	 *
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		try {
			query();
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
		return "ok";
	}

	/**
	 * @return the endTime
	 */
	public Timestamp getEndTime() {
		return endTime;
	}

	/**
	 * @return the innerCarUseInfoList
	 */
	public List<InnerVehicleUseInfo> getInnerCarUseInfoList() {
		return innerCarUseInfoList;
	}

	/**
	 * @return the innerVehicleList
	 */
	public List<InnerVehicle> getInnerVehicleList() {
		return innerVehicleList;
	}

	/**
	 * @return the staffAMPDataList
	 */
	public List<StaffDepApplyCarMData> getStaffAMPDataList() {
		return staffAMPDataList;
	}

	/**
	 * @return the startTime
	 */
	public Timestamp getStartTime() {
		return startTime;
	}

	/**
	 * @return the state
	 */
	public String getState() {
		return state;
	}

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @return the vehicleId
	 */
	public String getVehicleId() {
		return vehicleId;
	}

	/**
	 * @return the vehicleLevel
	 */
	public String getVehicleLevel() {
		return vehicleLevel;
	}

	/**
	 * @return the vehicleManageSerI
	 */
	public VehicleManageSerI getVehicleManageSerI() {
		return vehicleManageSerI;
	}

	/**
	 * @return the vehiclePicture
	 */
	public String getVehiclePicture() {
		return vehiclePicture;
	}

	public String qApplyedVehicle() {
		try {
			vehicleManageSerI.viewVehicleByState(state);
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
		return "qApplyedVehicle";
	}

	public String qNotUseVehicle() {
		try {
			vehicleManageSerI.viewVehicleByState(state);
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
		return "qVehicleNotUse";
	}

	public String query() {
		try {
			System.out.println(vehicleId + vehicleLevel + type);
			if (vehicleId != null && vehicleLevel != null && type != null
					&& state != null) {
				if (vehicleId.equals("") && vehicleLevel.equals("")
						&& type.equals("not") && state.equals("")) {
					innerVehicleList = vehicleManageSerI.viewAllVehicle();
					return "allConditionQuery";
				}
			}

			if (vehicleId != null)
				if (!vehicleId.equals("")) {
					innerVehicleList = new ArrayList<InnerVehicle>();
					innerVehicleList.add(vehicleManageSerI
							.viewVehicle(vehicleId));
					return "pConditionQuery";
				}

				else if (!type.equals("not")) {
					if (!state.equals("")) {
						innerVehicleList = vehicleManageSerI.viewVByStateType(
								state, type);
						return "pConditionQuery";
					} else if (state.equals("")) {
						innerVehicleList = vehicleManageSerI
								.viewVehicleByType(type);
						return "pConditionQuery";
					}
				} else if (!state.equals("")) {
					innerVehicleList = vehicleManageSerI
							.viewVehicleByState(state);
				}
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}

		return "ok";
	}

	public String queryByStateLeavel() {
		try {
			if (vehicleLevel == null)
				innerVehicleList = vehicleManageSerI
						.viewVehicleByState("notusing");
			else if (!vehicleLevel.equals("") && !vehicleLevel.equals("not"))
				innerVehicleList = vehicleManageSerI.viewVehicleByStateLeavel(
						vehicleLevel, "notusing");
			else if (vehicleLevel.equals("not"))
				innerVehicleList = vehicleManageSerI
						.viewVehicleByState("notusing");
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
		return "qbystateleavel";
	}

	public String queryVehicleAndDriver() {
		try {
			queryByStateLeavel();
			new QueryStaffAction().viewDriver();
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
		return "dispatch";
	}

	public String queryVUseInfo() {
		try {
			if (!vehicleId.equals("")) {
				innerCarUseInfoList = vehicleManageSerI.viewVUseInfo(vehicleId);
				return "ok";
			} else if (endTime != null && startTime != null) {
				if (!endTime.equals("") && !startTime.equals(""))// endTime离开时间
																	// startTime返回时间
					innerCarUseInfoList = vehicleManageSerI.viewVUseInfo(
							endTime, startTime);
			} else if (startTime != null && endTime == null)
				innerCarUseInfoList = vehicleManageSerI.viewVUseInfo(startTime);
			else if (startTime == null && endTime != null)
				innerCarUseInfoList = vehicleManageSerI.viewVUseInfo(endTime);
			else if (vehicleId.equals(""))
				innerCarUseInfoList = vehicleManageSerI.viewAllVUseInfo();
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
		return "queryVUseInfo";
	}

	/**
	 * @param endTime
	 *            the endTime to set
	 */
	public void setEndTime(Timestamp endTime) {
		this.endTime = endTime;
	}

	/**
	 * @param innerCarUseInfoList
	 *            the innerCarUseInfoList to set
	 */
	public void setInnerCarUseInfoList(
			List<InnerVehicleUseInfo> innerCarUseInfoList) {
		this.innerCarUseInfoList = innerCarUseInfoList;
	}

	/**
	 * @param innerVehicleList
	 *            the innerVehicleList to set
	 */
	public void setInnerVehicleList(List<InnerVehicle> innerVehicleList) {
		this.innerVehicleList = innerVehicleList;
	}

	/**
	 * @param staffAMPDataList
	 *            the staffAMPDataList to set
	 */
	public void setStaffAMPDataList(List<StaffDepApplyCarMData> staffAMPDataList) {
		this.staffAMPDataList = staffAMPDataList;
	}

	/**
	 * @param startTime
	 *            the startTime to set
	 */
	public void setStartTime(Timestamp startTime) {
		this.startTime = startTime;
	}

	/**
	 * @param state
	 *            the state to set
	 */
	public void setState(String state) {
		this.state = state;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @param vehicleId
	 *            the vehicleId to set
	 */
	public void setVehicleId(String vehicleId) {
		this.vehicleId = vehicleId;
	}

	/**
	 * @param vehicleLevel
	 *            the vehicleLevel to set
	 */
	public void setVehicleLevel(String vehicleLevel) {
		this.vehicleLevel = vehicleLevel;
	}

	/**
	 * @param vehicleManageSerI
	 *            the vehicleManageSerI to set
	 */
	public void setVehicleManageSerI(VehicleManageSerI vehicleManageSerI) {
		this.vehicleManageSerI = vehicleManageSerI;
	}

	/**
	 * @param vehiclePicture
	 *            the vehiclePicture to set
	 */
	public void setVehiclePicture(String vehiclePicture) {
		this.vehiclePicture = vehiclePicture;
	}

}
